package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.InvoiceDao;
import cn.itcast.domain.cargo.Invoice;
import cn.itcast.domain.cargo.InvoiceExample;
import cn.itcast.service.cargo.InvoiceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
// com.alibaba.dubbo.config.annotation.Service
@Service(timeout = 100000) // 如果要调试需要设置超时时间
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    private InvoiceDao invoiceDao;
    @Override
    public PageInfo<Invoice> findByPage(InvoiceExample InvoiceExample, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Invoice> invoiceList = invoiceDao.selectByExample(InvoiceExample);
        return new PageInfo<>(invoiceList);
    }

    @Override
    public List<Invoice> findAll(InvoiceExample InvoiceExample) {
        return invoiceDao.selectByExample(InvoiceExample);
    }

    @Override
    public Invoice findById(String id) {
        return invoiceDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Invoice invoice) {
        invoice.setStatus(0);
        invoiceDao.insertSelective(invoice);
    }

    @Override
    public void update(Invoice Invoice) {

    }

    @Override
    public boolean delete(String id) {
        Invoice invoice = invoiceDao.selectByPrimaryKey(id);
        Integer status = invoice.getStatus();
        if (status==0){
            invoiceDao.deleteByPrimaryKey(id);
            return true;
        }else {
            return false;
        }

    }


}
